import { expertInfoUpdateApi } from '/@/api/expertDatabase/expert';
import { ElLoading, ElMessageBox } from 'element-plus';
import router from '/@/router';
import { cancel } from '@cqdcg/admin/views/flow/task/cancel';
import { threeListDeleteApi } from '/@/api/threeList/declare';
import { revocation } from '@cqdcg/admin/views/flow/task/revocation';

export function useOperate(operateData?: any) {
	//移入黑名单
	const moveInBlackList = () => {
		ElMessageBox.prompt('移入黑名单理由', '提示', {
			confirmButtonText: '确定',
			inputPattern: /^(?!\s*$).+/,
			inputErrorMessage: '黑名单理由不能为空',
		}).then(({ value }) => {
			const loading = ElLoading.service({
				lock: true,
				text: '移入黑名单中...',
			});
			expertInfoUpdateApi({ expertInfoId: operateData.expertInfoId, reasonBlacklist: value, blacklist: '1' })
				.then(() => {
					// handleAfter();
				})
				.finally(() => {
					loading.close();
				});
		});
	};
	//移入出黑名单
	const moveOutBlackList = () => {
		ElMessageBox.confirm('是否确定移出黑名单?', '操作确认', {
			confirmButtonText: '确认',
			cancelButtonText: '取消',
			type: 'warning',
		}).then(() => {
			const loading = ElLoading.service({
				lock: true,
				text: '正在移出...',
			});
			expertInfoUpdateApi({ expertInfoId: operateData.expertInfoId, blacklist: '0', reasonBlacklist: '' })
				.then(() => {
					// handleAfter();
				})
				.finally(() => {
					loading.close();
				});
		});
	};
	//页面跳转
	const routerGo = (operateType: string) => {
		router.push({
			path: '/threeList/declare',
			query: {
				...operateData,
				operateType,
			},
		});
	};
	//删除
	const handleDelete = (handleAfter: any) => {
		ElMessageBox.confirm('是否确定删除?', '操作确认', {
			confirmButtonText: '确认',
			cancelButtonText: '取消',
			type: 'warning',
		}).then(() => {
			const loading = ElLoading.service({
				lock: true,
				text: '删除中...',
			});
			threeListDeleteApi({ threeListId: operateData.threeListId })
				.then(() => {
					handleAfter();
				})
				.finally(() => {
					loading.close();
				});
		});
	};
	//columuns
	const columns: any = [
		{ prop: 'threeListCode', label: '三张清单编号', width: 300 },
		{ prop: 'applicationCode', label: ' 应用编号', width: 300 },
		{ prop: 'threeListName', label: '三张清单名称', width: 300 },
		{ prop: 'constructTypeName', label: '建设类型', width: 300 },
		{ prop: 'belongDomainName', label: '所属领域', width: 200 },
		{ prop: 'responsibleDeptName', label: '责任部门', width: 200 },
		{ prop: 'teamLeaderUnitName', label: '专题组组长单位', width: 200 },
		{ prop: 'declarationTime', label: '申报时间', width: 300 },
		{ prop: 'noPassNumber', label: '不通过次数', width: 100 },
	];
	//撤销
	const handleCancel = (handleAfter: any) => {
		let obj = {
			processInstanceId: operateData.processInstanceId,
		};
		cancel(obj).then(() => {
			handleAfter();
		});
	};
	//审批人撤回
	const handleApprovalCancel = (handleAfter: any) => {
		let obj = {
			processInstanceId: operateData.processInstanceId,
		};
		revocation(obj).then(() => {
			handleAfter();
		});
	};
	return {
		moveInBlackList,
		moveOutBlackList,
		routerGo,
		handleDelete,
		columns,
		handleCancel,
		handleApprovalCancel,
	};
}
